package com.gency.subscribe.web.controller.system;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.gency.subscribe.model.system.UnitCategory;
import com.gency.subscribe.service.system.IUnitCategoryService;
import java.util.List;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

/**
 * <p>
 * 企业行业分类 前端控制器
 * </p>
 *
 * @author 马行空
 * @since 2018-06-12
 */
@Controller
@RequestMapping("/unitCategory")
public class UnitCategoryController {

	@Autowired
	private IUnitCategoryService unitCategoryService;
	
	/**
	 * 查询所有的一级分类
	 * @return
	 */
	@ResponseBody
	@GetMapping(value="/fistLeve")
	public List<UnitCategory> getFirstUnitCategory(){
		EntityWrapper<UnitCategory> entityWrapper = new EntityWrapper<>();
		entityWrapper.in("CODE", "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z");
		return unitCategoryService.selectList(entityWrapper);
	}
	
	
	/**
	 * 2级分类
	 * @param fistCode
	 * @return
	 */
	@ResponseBody
	@GetMapping(value="/secendLeve")
	public List<UnitCategory> getSecendUnitCategory(String fistCode){
		EntityWrapper<UnitCategory> entityWrapper = new EntityWrapper<>();
		entityWrapper.like("CODE",fistCode);
		List<UnitCategory> list = unitCategoryService.selectList(entityWrapper);
		if(CollectionUtils.isNotEmpty(list)){
			for (int i = 0; i <list.size(); i++) {
				if(list.get(i).getCode().getBytes().length !=3){
					list.remove(i);
				}
				
			}
		}
		return list;
	}
	
	/**
	 * 三级分类
	 * @param secendCode
	 * @return
	 */
	@ResponseBody
	@GetMapping(value="/threeLeve")
	public List<UnitCategory> getThreeUnitCategory(String secendCode){
		EntityWrapper<UnitCategory> entityWrapper = new EntityWrapper<>();
		entityWrapper.like("CODE",secendCode);
		List<UnitCategory> list = unitCategoryService.selectList(entityWrapper);
		if(CollectionUtils.isNotEmpty(list)){
			for (int i = 0; i <list.size(); i++) {
				if(list.get(i).getCode().getBytes().length !=4){
					list.remove(i);
				}
				
			}
		}
		return list;
	}
	
	/**
	 * 4级分类
	 * @param threedCode
	 * @return
	 */
	@ResponseBody
	@GetMapping(value="/fourLeve")
	public List<UnitCategory> getFourUnitCategory(String threedCode){
		EntityWrapper<UnitCategory> entityWrapper = new EntityWrapper<>();
		entityWrapper.like("CODE",threedCode);
		List<UnitCategory> list = unitCategoryService.selectList(entityWrapper);
		if(CollectionUtils.isNotEmpty(list)){
			for (int i = 0; i <list.size(); i++) {
				if(list.get(i).getCode().getBytes().length !=5){
					list.remove(i);
				}
				
			}
		}
		return list;
	}
	
}

